{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7f33e249-9eaf-4db9-aa70-0ef615c61eec",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "w= [[-0.71195672  0.62359524]] b= [0.591986]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "x=np.array([[2,3],[3,4],[6,5],[4,4],[3,2],[4,7],[5,4],[4,3],[7,5],[3,3],[4,4],[5,2]])\n",
    "y=np.array([[1],[1],[1],[1],[1],[1],[0],[0],[0],[0],[0],[0]])\n",
    "model=LogisticRegression()\n",
    "model.fit(x,y.ravel())\n",
    "print('w=',model.coef_,'b=',model.intercept_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "28634f59-ffba-4c40-bb5a-f204b571d34a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "模型预测准确率 0.75\n"
     ]
    }
   ],
   "source": [
    "x_test=np.array([[3,5],[2,4],[5,6],[3,6],[3,3],[4,5],[4,2],[5,5],[6,7],[5,3],[6,4],[6,6]])\n",
    "y_test=np.array([[1],[1],[1],[1],[1],[1],[0],[0],[0],[0],[0],[0]])\n",
    "r2=model.score(x_test,y_test)\n",
    "print(\"模型预测准确率\",r2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "bc65d2f9-2db3-4d9b-9ed9-eb0d622070aa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "新样本的预测标签 1\n"
     ]
    }
   ],
   "source": [
    "a=model.predict([[3,7]])\n",
    "print('新样本的预测标签',a[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8630a233-072c-4b6e-b0c2-3ca5dbce61bd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
